<template>
    <div>
        <div class="title">初始的数据</div>
        <div v-for="(item, index) in info" :key="index">
            <div style="margin:10px 0px;">姓名:{{ item.name }}</div>
        </div>
        <el-button type="primary" @click="changeList">数组对象id相同的被后者覆盖</el-button>

    </div>
</template>

<script>
export default {
    data() {
        return {
            info: [
                {
                    id: 11,
                    name: '赵云'
                },
                {
                    id: 22,
                    name: '张飞'
                },
                {
                    id: 11,
                    name: '关羽'
                },
            ]

        }
    },
    methods: {
        changeList() {
            // 对象包数组的用法
            let obj = {}
            this.info.forEach(item => {
                obj[item.id] = item
            })
            let b = Object.values(obj)
            this.info = b
            console.log(this.info, 42);
        }

    },
    created() {

    },
}
</script>
<style scoped lang="scss">
.title {
    font-size: 20px;
    margin-bottom: 8px;
    margin-top: 12px;
}
</style>